// MemoDlg.cpp : implementation file
//

#include "stdafx.h"
#include "dbfviewapp.h"
#include "MemoDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMemoDlg dialog


CMemoDlg::CMemoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMemoDlg::IDD, pParent)
{
	m_pSet = NULL;
	m_iFld = 0;
	m_iRec = 0;

	m_pctrlButton = NULL;

	//{{AFX_DATA_INIT(CMemoDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CMemoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMemoDlg)
	DDX_Control(pDX, IDOK, m_ctrlButtonOK);
	DDX_Control(pDX, IDC_EDIT_MEMO, m_ctrlMemoEdit);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CMemoDlg, CDialog)
	//{{AFX_MSG_MAP(CMemoDlg)
	ON_BN_CLICKED(IDOK, OnSave)
	ON_EN_CHANGE(IDC_EDIT_MEMO, OnChangeEditMemo)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMemoDlg message handlers

BOOL CMemoDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	m_pSet->SetAbsolutePosition(m_iRec);

	COleVariant varValue;
	m_pSet->GetFieldValue(m_iFld,varValue);
	
	if(varValue.vt == VT_BSTR)
	{
		CString m_strText = varValue.bstrVal; 

		m_ctrlMemoEdit.SetWindowText(m_strText);
	}
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CMemoDlg::OnSave() 
{
	CString m_strText;
	m_ctrlMemoEdit.GetWindowText(m_strText);

	m_pSet->SetAbsolutePosition(m_iRec);

	COleVariant varValue(m_strText);

	m_pSet->Edit();
	m_pSet->SetFieldValue(m_iFld,varValue);
	m_pSet->Update();


	if(m_pctrlButton != NULL)
	{
		CELL_DATA CellData;
		CellData.m_dwTag = 0;
		CellData.m_strText = m_strText;
		m_pctrlButton->SetData(CellData);
		m_pctrlButton->Invalidate();
	}

	CDialog::OnOK();
}

void CMemoDlg::OnChangeEditMemo() 
{
	m_ctrlButtonOK.EnableWindow(TRUE);	
}
